<?php
/**
 * Created by PhpStorm.
 * User: 17274
 * Date: 2018/4/13
 * Time: 14:36
 */

namespace app\admin\controller;

use app\admin\model\AppModel;
use think\Request;

class App extends Base
{
    protected $appModel;

    /*
     * 依赖注入Model
     * */
    public function __construct(AppModel $appModel){
        parent::__construct();
        $this->appModel=$appModel;
    }

    public function toastPost(){
        return [
            'code'=>'101',
            'msg'=>'请用POST方式请求'
        ];
    }

    public function renderResult($data){
        return [
            'code'=>'200',
            'msg'=>'请求成功',
            'data'=>$data
        ];
    }

    /*
     * 我的时间
     * 时间轴
     * */
    public function mine(){
        if(Request::instance()->isPost()){
            $timeline=$this->appModel->getTimeLine();
            return json($this->renderResult($timeline));
        }
        return json($this->toastPost());
    }

    /*
     * 记忆回廊
     * 相册分类
     * */
    public function album_label(){
        if(Request::instance()->isPost()){
            $album_label=$this->appModel->getAlbumNew();
            return json($this->renderResult($album_label));
        }
        return json($this->toastPost());
    }

    /*
    * 记忆回廊
    * 相册分类列表
    * 参数
    * ?label=xxx (测试废弃)
    * post : label=xxx
    * */
    public function album_list(){
        if(Request::instance()->isPost()){
            $label=input('post.label/s','none');
            $albums=$this->appModel->getAlbumByLabel($label);
            return json($this->renderResult($albums));
       }
       return json($this->toastPost());
    }

    /*
     * 图文档案和光影缝隙分类列表
     * category=article/video
     * */
    public function label(){
        if(Request::instance()->isPost()){
            $labels_c=input('post.category/s','none');
            $labels=$this->appModel->getLabels($labels_c);
            return json($this->renderResult($labels));
        }
        return json($this->toastPost());
    }



    /*
     *  图文档案列表
     * */
    public function article_list(){
        if(Request::instance()->isPost()){
            $labels_c=input('post.label/s','none');
            $article=$this->appModel->getArticleByLabel($labels_c);
            return json($this->renderResult($article));
        }
        return json($this->toastPost());
    }

    /*
     *  图文档案详细
     * */
    public function article_detail(){
        if(Request::instance()->isPost()){
            $id=input('post.id/d',-1);
            $article=$this->appModel->getArticleById($id);
            return json($this->renderResult($article));
        }
        return json($this->toastPost());
    }

    /*
  *  光影缝隙
  * */
    public function video_list(){
        if(Request::instance()->isPost()){
            $labels_c=input('post.label/s','none');
            $video=$this->appModel->getVideoByLabel($labels_c);
            return json($this->renderResult($video));
        }
        return json($this->toastPost());
    }

    /*
     *  光影缝隙详细
     * */
    public function video_detail(){
        if(Request::instance()->isPost()){
            $id=input('post.id/d',-1);
            $video=$this->appModel->getVideoById($id);
            return json($this->renderResult($video));
        }
        return json($this->toastPost());
    }
}